package com.baiqian.doupo.command;

import com.baiqian.doupo.Utils;
import com.baiqian.doupo.capability.DouPoModCapability;
import com.baiqian.doupo.capability.douqi.IDouQiCapability;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.common.util.LazyOptional;

public class AddDouQiCommand implements Command<CommandSource> {
    public static AddDouQiCommand instance = new AddDouQiCommand();

    @Override
    public int run(CommandContext<CommandSource> context) {
        LazyOptional<IDouQiCapability> douQiCap = context.getSource().getEntity().getCapability(DouPoModCapability.DOUQI_CAPABILTTY);

        if(douQiCap.isPresent()){
            douQiCap.ifPresent((l) -> {
                l.setDouQi(l.getDouQi(1)+context.getArgument("number",Double.class),1, (PlayerEntity) context.getSource().getEntity());
            });
        }
        context.getSource().sendFeedback(new TranslationTextComponent("cmd." + Utils.MOD_ID + ".add_douqi",context.getArgument("number",Double.class)), false);
        return 0;
    }
}
